import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { GraphQLModule } from '@nestjs/graphql';
import { join } from 'path';
import { doctypeService } from './doctype/doc.type.service';
import { doctypeResolver } from './doctype/doc.type.resolver';
import { EmrDocTypeEntity } from './entities/emr.doc.type.entity';
import { EmrTeetEntity } from './entities/emr.teet.entity';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mongodb',
      host: 'localhost',
      port: 27017,
      database: 'test', // 数据库名
      entities: [join(__dirname, '**/entities/*.{ts,js}')], // 需要自动实体映射的文件路径匹配
      useNewUrlParser: true, // 使用新版mongo连接Url解析格式
      synchronize: true, // 自动同步数据库生成entity
    }),
    GraphQLModule.forRoot({
      //autoSchemaFile: './schema.gql', //代码先行(既先写实体定义)
      typePaths: ['./gql-schema/*.graphql'],
      //autoSchemaFile:'../gql-schema/*.graphql',
      debug: true,
      playground: true,
      introspection: true,
      context: ({ req }) => ({ req }), // 一定要这里设置req到上下文中，否则在guard中是拿不到这个req参数的
    }),
    TypeOrmModule.forFeature([
      EmrDocTypeEntity,
      EmrTeetEntity]),
  ],
  // controllers: [AppController],
  providers: [doctypeService, doctypeResolver],
})
export class AppModule {}
